package com.tony.dao.impl;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.tony.dao.AccountDAO;
import com.tony.dataobject.AccountDO;

public class IbatisAccountDAO extends SqlMapClientDaoSupport implements AccountDAO {

    @Override
    public void insert(AccountDO accountDO) {

        if (accountDO == null) {
            throw new IllegalArgumentException("Can't insert a null data object into db.");
        }

        getSqlMapClientTemplate().insert("insertAccount", accountDO);
    }

    @Override
    public AccountDO queryByEmail(String email) {
        return (AccountDO) getSqlMapClientTemplate().queryForObject("queryByEmail", email);
    }

    @Override
    @SuppressWarnings("unchecked")
    public List<AccountDO> queryAll() {
        return getSqlMapClientTemplate().queryForList("queryAll");
    }

    @Override
    public void update(AccountDO accountDO) {
        getSqlMapClientTemplate().update("updateByEmail", accountDO);
    }

    @Override
    public AccountDO lockByEmail(String email) {
        return (AccountDO) getSqlMapClientTemplate().queryForObject("lockByEmail", email);
    }

}
